﻿using PTop.Code;
using PTop.Domain.Entity.Biz;
using PTop.Domain.IRepository.Biz;
using PTop.Repository.Biz;
using System.Collections.Generic;

namespace PTop.Application.Biz
{
    /// <summary>
    /// 工作招聘App
    /// </summary>	
    public class JobRecruitApp
    {
        private IJobRecruitRepository service = new JobRecruitRepository();

        public List<JobRecruitEntity> GetList(Pagination pagination, string keyword, int state)
        {
            var expression = ExtLinq.True<JobRecruitEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.F_JobTitle.Contains(keyword));
                expression = expression.Or(t => t.F_JobRequirement.Contains(keyword));
            }
            if (state > -1)
            {
                expression = expression.And(t => t.F_State == state);
            }
            return service.FindList(expression, pagination);
        }

        public JobRecruitEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }

        public void Delete(string keyValue)
        {
            service.Delete(t => t.F_Id == keyValue);
        }

        public void SubmitForm(JobRecruitEntity entity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                entity.Modify(keyValue);
                service.Update(entity);
            }
            else
            {
                entity.Create();
                //entity.F_LastModifyTime = entity.F_CreatorTime;
                //entity.F_LastModifyUserId = entity.F_CreatorUserId;
                service.Insert(entity);
            }
        }

        #region For Front

        public List<JobRecruitEntity> GetList(int pageIndex)
        {
            var pagination = new Pagination
            {
                page = pageIndex,
                rows = 10,
                sidx = "F_CreatorTime desc",
                sord = "asc"
            };
            var expression = ExtLinq.True<JobRecruitEntity>();
            expression = expression.And(t => t.F_State == 1);
            return service.FindList(expression, pagination);
        }

        #endregion

    }
}